<?php

namespace App\Http\Controllers;

use App\Models\Project;
use App\Models\ProjectMeeting;
use App\Models\ProjectMeetingInvitationSpeaker;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class UserProjectController extends BaseController
{
    /**
     * 项目列表
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-10-09
     * @param Request $request
     * @return void
     */
    public function projectList(Request $request)
    {
        $rules = [
            'page' => ['required'],
            'limit' => ['required'],
        ];

        $message = [
            'page.required' => '页码不能为空',
            'limit.required' => '限制条数不能为空',
        ];

        $payload = $request->only('page', 'limit', 'project_name', 'service', 'project_status', 'create_time');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }
        $model = new Project();

        $list = $model->getProjectList($payload, userId());
        return successPaginate($list);
    }


    /**
     * 个人中心-项目列表-会议管理
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-11-22
     * @param Request $request
     * @return void
     */
    public function projectMeetingList(Request $request)
    {
        $rules = [
            'page' => ['required'],
            'limit' => ['required'],
        ];

        $message = [
            'page.required' => '页码不能为空',
            'limit.required' => '限制条数不能为空',
        ];

        $payload = $request->only('page', 'limit', 'project_id', 'meeting_name', 'meeting_status', 'create_time');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }

        $projectMeeting = new ProjectMeeting();

        $list = $projectMeeting->getProjectMeetingById($payload);
        return successPaginate($list);
    }


    /**
     * 个人中心-项目列表-会议管理-讲者信息列表
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-11-22
     * @param Request $request
     * @return void
     */
    public function projectMeetingSpeakerList(Request $request)
    {
        $rules = [
            'page' => ['required'],
            'limit' => ['required'],
            'project_id' => ['required'],
            'project_meeting_id' => ['required'],
        ];

        $message = [
            'page.required' => '页码不能为空',
            'limit.required' => '限制条数不能为空',
            'project_id.required' => '缺少参数项目ID',
            'project_meeting_id.required' => '缺少参数项目会议ID',
        ];

        $payload = $request->only('page', 'limit', 'project_id', 'project_meeting_id', 'speaker_name', 'meeting_type', 'create_time');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }

        $projectMeetingSpeaker = new ProjectMeetingInvitationSpeaker();
        $list = $projectMeetingSpeaker->getProjectMeetingInvitationSpeakerList($payload);

        return success($list);
    }


    /**
     * 个人中心-项目列表-会议管理-讲者信息列表-专家邀请阶段信息
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-11-25
     * @param Request $request
     * @return void
     */
    public function projectMeetingSpeakerInvitation(Request $request)
    {
        $rules = [
            'id' => ['required'],

        ];

        $message = [
            'id.required' => '缺少参数ID',
        ];

        $payload = $request->only('id');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }

        $projectMeetingSpeakerInvitation = new ProjectMeetingInvitationSpeaker();

        $info = $projectMeetingSpeakerInvitation->getSpeakerInvitationDetail($payload['id']);
        return success($info);
    }


    /**
     * 获取讲者沟通阶段
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-11-25
     * @param Request $request
     * @return void
     */
    public function projectMeetingSpeakerConnect(Request $request)
    {
        $rules = [
            'id' => ['required'],
            'meeting_type' => ['required'],

        ];

        $message = [
            'id.required' => '缺少参数ID',
            'meeting_type.required' => '缺少参数会议类型',
        ];

        $payload = $request->only('id', 'meeting_type');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }

        $projectMeetingSpeakerInvitation = new ProjectMeetingInvitationSpeaker();

        $info = $projectMeetingSpeakerInvitation->getSpeakerConnectDetail($payload['id'], $payload['meeting_type']);
        return success($info);
    }
}
